package com.wzg.security.http;

import java.net.HttpURLConnection;
import java.net.SocketTimeoutException;
import java.net.URL;

/**
 * @author henryGui
 * @version V1.0
 * @Title: TestUrlConn
 * @Package com.wzg.security.http
 * @Description: TODO
 * @date 2018-07-13 上午9:55
 */
public class TestUrlConn {

    public static void main(String[] args) throws Exception {
//        System.out.println(testWsdlConnection("http://bx.glsafesports.com/payment/tiandaocallback"));
        System.out.println(testWsdlConnection("https://jttp.cpic.com.cn:8443/jttp/itxsvc/param"));
    }

    public static int testWsdlConnection(String address) throws Exception {
        int status = 404;
        try {
            URL urlObj = new URL(address);
            HttpURLConnection oc = (HttpURLConnection) urlObj.openConnection();
            oc.setUseCaches(false);
            oc.setConnectTimeout(3000); // 设置超时时间
            status = oc.getResponseCode();// 请求状态
            if (200 == status) {
                // 200是请求地址顺利连通。。
                return status;
            }
        } catch (SocketTimeoutException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return status;
    }
}
